var t = require("../../api.js"), i = require("../../area-picker/area-picker.js"), e = getApp(), o = !1;

Page({
  data: {
    name: "",
    mobile: "",
    detail: "",
    district: null,
  },
  onLoad: function (a) {
    e.pageOnLoad(this, a);
    console.log(a)
    var d = this;
    d.getDistrictData(function (t) {
      i.init({
        page: d,
        data: t
      });
    }), d.setData({
      shop_id: a.shop_id
    }), a.shop_id && (wx.showLoading({
      title: "正在加载",
      mask: !0
    }), e.request({
      url: t.commander.shop_set,
      data: {
        id: a.shop_id
      },
      success: function (t) {
        var peisong_type= t.data.peisong_type ? JSON.parse(t.data.peisong_type) : {}
        console.log(t.shop_time)
        wx.hideLoading(), 0 == t.code && d.setData({
          shop:t.data,
          name: t.data.name,
          mobile: t.data.mobile,
          wx_code: t.data.wx_code,
          address: t.data.address,
          pic_url: t.data.pic_url,
          shop_time_end: t.shop_time[1],
          shop_time_start: t.shop_time[0],
          default_peisong_type: t.data.default_peisong_type,
          peisong_type2: t.data.peisong_type,
          peisong_type: peisong_type,
          shequimg: t.data.pic_url,
          bili: t.bili,
          shop_time:t.shop_time,
          shop_time_minute:t.shop_time_minute,
          shop_time_end_minute: t.shop_time_minute[1],
          shop_time_start_minute: t.shop_time_minute[0],
        });
        console.log(t.data.default_peisong_type)
        if(t.data.default_peisong_type ==1){
          d.setData({
            z_type: true,
            s_type: false,
            k_type: false,
          });
        } else if (t.data.default_peisong_type == 2){
          d.setData({
            z_type: false,
            s_type: true,
            k_type: false,
          });
        }else{
          d.setData({
            z_type: false,
            s_type: false,
            k_type: true,
          });
        }
      }
    }));
  },
  getDistrictData: function (i) {
    var a = wx.getStorageSync("district");
    if (!a) return wx.showLoading({
      title: "正在加载",
      mask: !0
    }), void e.request({
      url: t.default.district,
      success: function (t) {
        wx.hideLoading(), 0 == t.code && (a = t.data, wx.setStorageSync("district", a),
          i(a));
      }
    });
    i(a);
  },
  onAreaPickerConfirm: function (t) {
    this.setData({
      district: {
        province: {
          id: t[0].id,
          name: t[0].name
        },
        city: {
          id: t[1].id,
          name: t[1].name
        },
        district: {
          id: t[2].id,
          name: t[2].name
        }
      }
    });
  },
  saveAddress: function () {
    var i = this, a = /^(\d{3,4}-\d{6,9})$/, d = /^\+?\d[\d -]{8,12}\d/;
    console.log(i.data)
    wx.showLoading({
      title: "正在保存",
      mask: !0
    });
     e.request({
       url: t.commander.shop_save,
      method: "post",
      data: {
        name: i.data.name,
        mobile: i.data.mobile,
        wx_code:i.data.wx_code,
        address: i.data.address,
        peisong_type: i.data.peisong_type2,
        default_peisong_type: i.data.default_peisong_type,
        pic_url: i.data.pic_url,
        shop_time_start: i.data.shop_time_start,
        shop_time_end: i.data.shop_time_end,
        shop_time_start_minute: i.data.shop_time_start_minute,
        shop_time_end_minute: i.data.shop_time_end_minute,
        shop_id: i.data.shop_id
      },
      success: function (t) {
        wx.hideLoading(), 0 == t.code && wx.showModal({
          title: "提示",
          content: t.msg,
          showCancel: !1,
          success: function (t) {
            t.confirm && wx.navigateBack();
          }
        }), 1 == t.code && wx.showToast({
          title: t.msg,
          image: "/images/icon-warning.png"
        });
      }
    });
  },
  inputBlur: function (t) {
    var i = '{"' + t.currentTarget.dataset.name + '":"' + t.detail.value + '"}';
    this.setData(JSON.parse(i));
    console.log(i)
  },
  checkboxChange: function (t) {
    var i = '{"peisong_type2":"' + t.detail.value + '"}';
    this.setData(JSON.parse(i));
    console.log(i)
  },
  radioChange: function (t) {
    console.log(t)
    var i = '{"default_peisong_type":"' + t.detail.value + '"}';
    console.log(i)
    this.setData(JSON.parse(i));
  },
  getWechatAddress: function (i) {
    var a = this;
    wx.chooseAddress({
      success: function (i) {
        "chooseAddress:ok" == i.errMsg && (wx.showLoading(), e.request({
          url: t.user.wechat_district,
          data: {
            national_code: i.nationalCode,
            province_name: i.provinceName,
            city_name: i.cityName,
            county_name: i.countyName
          },
          success: function (t) {
            1 == t.code && wx.showModal({
              title: "提示",
              content: t.msg,
              showCancel: !1
            }), a.setData({
              name: i.userName || "",
              mobile: i.telNumber || "",
              detail: i.detailInfo || "",
              district: t.data.district
            });
          },
          complete: function () {
            wx.hideLoading();
          }
        }));
      }
    });
  },
  onReady: function () { },
  onShow: function () {
    e.pageOnShow(this);
  },
  uploadImg: function (t) {
    var a = this, i = t.currentTarget.dataset.index, s = a.data.form;
    o = !0, e.uploader.upload({
      start: function () {
        wx.showLoading({
          title: "正在上传",
          mask: !0
        });
      },
      success: function (t) {
        console.log(t)
        if(t.code == 0){
          var i = '{"pic_url":"' + t.data.url + '"}';
          console.log(i)
          a.setData(JSON.parse(i));
          a.setData({
            shequimg:t.data.url
          })
          a.showToast({
            title: t.msg
          });
        }
      },
      error: function (t) {
        a.showToast({
          title: t
        });
      },
      complete: function () {
        wx.hideLoading();
      }
    });
  }
});